{% extends "people/profile_base.html" %}
{% load static %}
{% load i18n %}
{% load avatar_tags %}
{% load activity_tags %}
{% load pagination_tags %}

{% block title %} {% trans "Profile of " %}{{ profile.first_name|default:profile.username }}{% endblock %}

{% block head %}
  {% if TWITTER_CARD %}
    {% include "people/_profile_twittercard.html" %}
  {% endif %}
  {% if OPENGRAPH_ENABLED %}
    {% include "people/_profile_opengraph.html" %}
  {% endif %}
  {{ block.super }}
{% endblock %}

{% block body_class %}people explore{% endblock %}

{% block body %}

<div class="page-header">
  <h2 class="page-title">{{ profile.name_long }}</h2>
</div>

<div class="col-xs-3 col-md-2 profile-image">
  {% autoescape off %}{% avatar profile 240 %}{% endautoescape %}
</div>

<div class="col-xs-9 col-md-7 profile-details">

{% if user.is_authenticated %}
{% if user == profile %}
  {% for group in profile.group_list_all %}
  <div ng-if="group.logo_url != ''" class="col-xs-1 pull-right group-logo">
    <a href="{{ group.get_absolute_url }}" ><img src="{{ group.logo_url }}" alt="{{ group.title }}" /></a>
  </div>
  <!-- <div class="col-xs-6 col-md-8">
    <h5>
      <a href="{{ group.get_absolute_url }}">{{ group.title }}</a>
      {% if group.email %} <a href="mailto:{{ group.email }}"><i class="fa fa-envelope-o"></i></a>{% endif %}
    </h5>
  </div> -->
  {% endfor %}
{% else %}
  {% for group in profile.group_list_public %}
  <div ng-if="group.logo_url != ''" class="col-xs-1 pull-right group-logo">
    <a href="{{ group.get_absolute_url }}" ><img src="{{ group.logo_url }}" alt="{{ group.title }}" /></a>
  </div>
  <!-- <div class="col-xs-6 col-md-8">
    <h5>
      <a href="{{ group.get_absolute_url }}">{{ group.title }}</a>
      {% if group.email %} <a href="mailto:{{ group.email }}"><i class="fa fa-envelope-o"></i></a>{% endif %}
    </h5>
  </div> -->
  {% endfor %}
{% endif %}
{% endif %}

  <h3>{{ profile.first_name|default:profile.name_long }}</h3>
  <table class="table table-user-profile">
    <tbody>
      {% if user.is_authenticated and user == profile or user.is_superuser or user.is_staff %}
      {% if SHOW_PROFILE_EMAIL %}
      <tr>
        <td class="table-user-profile-attribute">{% trans 'Email' %}</td>
        {% if profile.email %}
            <td><a href="mailto:{{ profile.email }}">{{ profile.email }}</a></td>
        {% else %}
            <td>{% trans 'Not provided.' %}</td>
        {% endif %}
      </tr>
      {% endif %}
      <tr>
        <td class="table-user-profile-attribute">{% trans 'Organization'  %}</td>
        <td>{{ profile.organization | default:_('Not provided.') }}</td>
      </tr>
      <tr>
        <td class="table-user-profile-attribute">{% trans 'Description' %}</td>
        <td>{{ profile.profile | default:_('Not provided.') }}</td>
      </tr>
      <tr>
        <td class="table-user-profile-attribute">{% trans 'Position Name' %}</td>
        <td>{{ profile.position | default:_('Not provided.') }}</td>
      </tr>
      <tr>
        <td class="table-user-profile-attribute">{% trans 'Location' %}</td>
        <td>{{ profile.location | default:_('Not provided.') }}</td>
      </tr>
      <tr>
        <td class="table-user-profile-attribute">{% trans 'Voice' %}</td>
        {% if profile.voice %}
            <td><a href="tel:{{ profile.voice }}">{{ profile.voice }}</a></td>
        {% else %}
            <td>{% trans "Not provided" %}.</td>
        {% endif %}
      </tr>
      <tr>
        <td class="table-user-profile-attribute">{% trans 'Fax' %}</td>
        <td>{{ profile.fax | default:_('Not provided.') }}</td>
      </tr>
      <tr>
        <td class="table-user-profile-attribute">{% trans 'Keywords' %}</td>
        <td>
            {% if profile.keyword_list %}
                {% for keyword in profile.keyword_list %}
                    <span class="label label-default">{{ keyword }}</span>
                {% endfor %}
            {% else %}
                {% trans 'Not provided' %}
            {% endif %}
        </td>
      </tr>
      {% else %}
      <tr>
        <td class="table-user-profile-attribute">{% trans 'Organization'  %}</td>
        <td>{{ profile.organization | default:_('Not provided.') }}</td>
      </tr>

      {% endif %}
    </tbody>
  </table>
  {% if USE_GEOSERVER and DISPLAY_WMS_LINKS %}
  <p>
      {% if request.user.is_authenticated and access_token %}
        <a href="{% url 'capabilities_user' profile.username %}?access_token={{access_token}}">
      {% else %}
        <a href="{% url 'capabilities_user' profile.username %}">
      {% endif %}
      <i class="fa fa-map"></i> {% trans 'User layers WMS GetCapabilities document' %}</a></p>
  {% endif %}
</div>

<div class="col-xs-12 col-md-3">
  <ul class="list-group">
      <li class="list-group-item"><a href="{% url "message_create" profile.pk %}"><i class="fa fa-paper-plane-o"></i> {% trans "Message User" %}</a></li>
    </ul>
  {% if user == profile %}
    <ul class="list-group">
      {% if not READ_ONLY_MODE %}
        <li class="list-group-item"><a href="{% url "profile_edit" user.username %}"><i class="fa fa-edit"></i> {% trans "Edit profile" %}</a></li>
      {% endif %}
      {% if not AVAILABLE_SOCIAL_APPS_COUNT == 0 %}
        <li class="list-group-item"><a href="{% url "socialaccount_connections" %}"><i class="fa fa-sign-in"></i> {% trans "Connected social accounts" %}</a></li>
      {% endif %}
        <li class="list-group-item"><a href="{% url "account_email" %}"><i class="fa fa-envelope-o"></i> {% trans "Associated e-mails" %}</a></li>
      {% if not READ_ONLY_MODE %}
        <li class="list-group-item"><a href="{% url "account_change_password" %}"><i class="fa fa-lock"></i> {% trans "Set/Change password" %}</a></li>
      {% endif %}
    </ul>
    <ul class="list-group">
      <li class="list-group-item"><a href="{% url "user-activity" profile.username %}"><i class="fa fa-fire"></i> {% trans "My Activities" %}</a></li>
    </ul>
    <ul class="list-group">
      {% if USE_NOTIFICATIONS %}
      <li class="list-group-item"><a href="{% url "pinax_notifications:notice_settings" %}"><i class="fa fa-bell"></i> {% trans "Notifications" %}</a></li>
      {% endif %}
      {% if perms.announcements.can_manage %}
      <li class="list-group-item"><a href="{% url "announcements_list" %}"><i class="fa fa-bullhorn"></i> {% trans "Announcements" %}</a></li>
      {% endif %}
    </ul>
    <ul class="list-group">
      {% if not READ_ONLY_MODE %}
        <li class="list-group-item"><a href="{% url "geonode.invitations:geonode-send-invite" %}"><i class="fa fa-edit"></i> {% trans "Invite Users" %}</a></li>
      {% endif %}
      {% if user.is_superuser or user.is_staff %}
          <li class="list-group-item"><a href="{{ OGC_SERVER.default.WEB_UI_LOCATION }}"><i class="fa fa-gears"></i> {% trans "GeoServer" %}</a></li>
          <li class="list-group-item"><a href="{% url "admin:index" %}"><i class="fa fa-cog"></i> {% trans "Admin" %}</a></li>
      {% endif %}
    </ul>
  {% else %}
    {% if user.is_superuser and not READ_ONLY_MODE %}
    <ul class="list-group">
      <li class="list-group-item"><a href="{% url "profile_edit" profile.username %}"><i class="fa fa-edit"></i> {% trans "Edit profile" %}</a></li>
    </ul>
    {% endif %}
    <ul class="list-group">
      <li class="list-group-item"><a href="{% url "user-activity" profile.username %}"><i class="fa fa-fire"></i> {% trans "User Activities" %}</a></li>
    </ul>
  {% endif %}
</div>

<div class="col-xs-12 col-md-9">
  <h4>{% trans "Resources" %}</h4>
  <div class="col-md-12">
    {% include "people/_profile_filters.html" %}
  </div>
  <!-- <div class="col-md-12">
    {% include "search/_sort_filters.html" %}
  </div> -->
  <div class=" col-xs-12 col-md-12">
    {% include 'base/_resourcebase_snippet.html' %}
  </div>
  <div class="col-md-12">
    {% include 'search/_pagination.html' %}
  </div>
</div>

{% endblock %}

{% block extra_script %}
{{ block.super }}
  <script type="text/javascript">
      {% if HAYSTACK_SEARCH %}
          SEARCH_URL = '{% url 'api_get_search' api_name='api' resource_name='base' %}?owner__username={{profile.username}}'
      {% else %}
          SEARCH_URL = '{% url 'api_dispatch_list' api_name='api' resource_name='base' %}?owner__username={{profile.username}}';
      {% endif %}
  </script>
  {% include 'search/search_scripts.html' %}
{% endblock %}
